// HidISPDlg.h : header file
//

#pragma once
#include "afxcmn.h"
#include "../HidLoader/HidLoader.h"
//#include "HidLoader.h"
#include "treecombo.h"
#include "afxwin.h"

// CHidISPDlg dialog
class CHidISPDlg : public CDialog, public CHIDLoader, public IProgressRender
{
// Construction
public:
	CHidISPDlg(CWnd* pParent = NULL);	// standard constructor

// Dialog Data
	enum { IDD = IDD_HIDISP_DIALOG };

	protected:
	virtual void DoDataExchange(CDataExchange* pDX);	// DDX/DDV support


// Implementation
protected:
	HICON m_hIcon;

	// Generated message map functions
	virtual BOOL OnInitDialog();
	afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
	afx_msg void OnPaint();
	afx_msg HCURSOR OnQueryDragIcon();
	DECLARE_MESSAGE_MAP()
public:
    CProgressCtrl m_progress;
    virtual void OnReadData(BYTE* pData, size_t dataLen);
public:
    afx_msg void OnBnClickedLoadFile();
public:
    afx_msg void OnBnClickedUpdate();
public:
    CTreeCombo m_regCfg;
protected:
    virtual void OnOK();
public:
    afx_msg void OnBnClickedUpdateConfig();
public:
    afx_msg void OnBnClickedReadConfig();
    virtual	void	OnConnect(LPCTSTR path);
    virtual	void	OnDisconnect(LPCTSTR path);
    virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
    void TitleConnect();
    void TitleDisconnect();
    virtual void OnStartProg();

    virtual void OnStopProg();
public:
    afx_msg void OnBnClickedReset2aprom();
public:
    afx_msg void OnBnClickedReset2ldrom();
public:
    CComboBox m_log;
public:
    afx_msg void OnBnClickedGenFirmware();

protected:
    BYTE IsBootloaderRunning();
    void EnterConfigMode();
    void CHidISPDlg::Reset2LDROM();
    void CHidISPDlg::Reset2APROM();

public:
    virtual void SetRange(int start, int end);
    virtual void SetPos(int pos);
};

#ifndef TAG_CONFIGPROG
#define  CFG0_ADDR		0x00300000
#define  CFG1_ADDR      0x00300004
typedef unsigned long uint32_t;
typedef struct tagConfigProg
{
	uint32_t   bRead;      // zero mean write, none zero means read
	uint32_t   config0;    // value for config 0
	uint32_t   config1;    // value for config 1
	uint32_t   dummy[13];  // reserved
}ConfigProg_t,*PConfigProg_t;

#define  INITIAL_PROG			0x05	   /* get string request to initial program */
#define  CONFIG_PROG            0x06       /* get string request to start config word program */
#define  RESET2APROM			0x07       /* reset to APROM */
#define  RESET2LDROM            0x08	   /* reset to LDROM */
#endif